﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
             xmlns:convert="clr-namespace:Opds_Viewer.Converter"
             xmlns:control="clr-namespace:Opds_Viewer.Control"
             x:Class="Opds_Viewer.View.CatalogView"
             mc:Ignorable="d" 
			 d:DesignHeight="600" d:DesignWidth="800"
             DataContext="{Binding Catalog, Mode=OneWay, Source={StaticResource Locator}}">
	
    <UserControl.Resources>
        <convert:CommentBookConverter x:Key="CommentBookConverter" />
        <convert:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
    </UserControl.Resources>
	
	<i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <cmd:EventToCommand Command="{Binding LoadBooksCommand, Mode=OneWay}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>               
	
    <Grid>
    	<Grid.RowDefinitions>
    		<RowDefinition Height="70"/>
    		<RowDefinition Height="*"/>
    		<RowDefinition Height="70"/>
    	</Grid.RowDefinitions>
    	<Grid.ColumnDefinitions>
    		<ColumnDefinition Width="0.4*"/>
    		<ColumnDefinition Width="0.6*"/>
    	</Grid.ColumnDefinitions>
		
		<TextBlock x:Name="CurrentCatalog" HorizontalAlignment="Left"
				   Margin="20,5,0,0" TextWrapping="Wrap" Text="{Binding BreadCrumbs}"
				   d:LayoutOverrides="Height" VerticalAlignment="Top" Foreground="{DynamicResource BookTitleTextColor}" FontSize="14.667" FontWeight="Bold" FontStyle="Italic"/>
		
		<Grid x:Name="List" Grid.Column="0" Margin="0,0,10,0" Grid.Row="1">
			<Grid.RowDefinitions>
				<RowDefinition Height="30"/>
				<RowDefinition Height="30"/>
				<RowDefinition Height="*"/>
				<RowDefinition Height="30"/>
			</Grid.RowDefinitions>
			
			<StackPanel x:Name="SearchPanel" Orientation="Horizontal" VerticalAlignment="Center">
				<TextBlock x:Name="SearchLabel" TextWrapping="Wrap" Text="Search" VerticalAlignment="Center"/>
                <TextBox x:Name="Search" Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" Width="150" Margin="10,0">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="KeyUp">
                            <cmd:EventToCommand Command="{Binding FilterBookCommand, Mode=OneWay}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </TextBox>
                <ComboBox x:Name="SearchOption" Width="70" HorizontalAlignment="Right" SelectedValue="{Binding FilterType, Mode=TwoWay}" SelectedValuePath="Content">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SelectionChanged">
                            <cmd:EventToCommand Command="{Binding FilterBookCommand, Mode=OneWay}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                	<ComboBoxItem Content="Title" IsSelected="True"/>
                	<ComboBoxItem Content="Author"/>
                	<ComboBoxItem Content="Serie"/>
                </ComboBox>
            </StackPanel>
			
			<Button x:Name="AdvancedSearch" Content="Advanced" HorizontalAlignment="Left"  Grid.Row="1" VerticalAlignment="Center" Visibility="Collapsed"/>
			
			<ListBox x:Name="EbookBox" Grid.Row="2"
					 ItemTemplate="{DynamicResource ListEbookItemTemplate}"
					 ItemsSource="{Binding OBooks, Mode=OneWay}"
					 SelectedItem="{Binding SelectedBook, Mode=TwoWay}"
					 Background="Transparent" BorderBrush="Transparent" BorderThickness="0" Margin="0,10">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <cmd:EventToCommand Command="{Binding LoadCoverCommand, Mode=OneWay}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </ListBox>
            
            <Button x:Name="DownloadButton" Grid.Row="3" Content="Download" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="Collapsed"/>
		</Grid>
		
		<Grid x:Name="Details" Margin="10,0" Grid.Row="1" Grid.Column="1">
			<Grid.RowDefinitions>
				<RowDefinition Height="70"/>
				<RowDefinition Height="0.464*"/>
				<RowDefinition Height="0.536*"/>
				<RowDefinition Height="40"/>
			</Grid.RowDefinitions>
			
			<Grid Grid.Row="1">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition Width="*"/>
				</Grid.ColumnDefinitions>
				<Image x:Name="CoverImage" Source="{Binding CurrentCover}" VerticalAlignment="Top" HorizontalAlignment="Left" d:LayoutOverrides="GridBox" />
				<control:LoadingAnimation Visibility="{Binding IsLoadingCover, Converter={StaticResource BoolToVisibilityConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" d:LayoutOverrides="GridBox"/>
				<StackPanel Orientation="Vertical" Margin="10,10,0,0" Grid.ColumnSpan="2" Grid.Column="1">
					<TextBlock x:Name="Title" Text="{Binding SelectedBook.Title}" Foreground="{DynamicResource BookTitleTextColor}" FontSize="32" FontFamily="Georgia" TextWrapping="Wrap"/>
					<StackPanel x:Name="AuthorPanel" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,20,0,0">
						<TextBlock Text="{Binding SelectedBook.Author.FirstName}" Foreground="{DynamicResource MainColorApplication}" FontFamily="Verdana" FontSize="18.667"/>
						<TextBlock Text=" " Foreground="{DynamicResource MainColorApplication}" FontSize="18.667" FontFamily="Verdana"/>
						<TextBlock Text="{Binding SelectedBook.Author.Name}" Foreground="{DynamicResource MainColorApplication}" FontFamily="Verdana" FontSize="18.667"/>
					</StackPanel>
				</StackPanel>
			</Grid>	
            
			<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto" Grid.ColumnSpan="2" Margin="0,10,0,0">
				<TextBlock x:Name="Summary" TextWrapping="Wrap"
					Text="{Binding SelectedBook.Summary, Converter={StaticResource CommentBookConverter}}" Foreground="{DynamicResource ContentTextColor}" FontSize="14.667" FontFamily="Georgia" />
			</ScrollViewer>
                
		</Grid>
    </Grid>
</UserControl>
